package neusoft.example.com.yuejian06.Fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;
import com.youth.banner.loader.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import neusoft.example.com.yuejian06.Adapter.ActivityListAdapter;
import neusoft.example.com.yuejian06.Bean.Activity;
import neusoft.example.com.yuejian06.Model.ActivityListModel;
import neusoft.example.com.yuejian06.R;
import neusoft.example.com.yuejian06.RetrofitListener;

/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityFragment extends Fragment {
    private Banner banner;
    private ArrayList<String> listPath;

    private RecyclerView recyclerView;
    private ActivityListModel activityListModel;
    private RetrofitListener<List<Activity>> listener;
    private LinearLayoutManager linearLayoutManager;
    private ActivityListAdapter activityAdapter;

    public ActivityFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_activity,container,false);
        activityAdapter=new ActivityListAdapter();
        recyclerView=(RecyclerView)view.findViewById(R.id.activity_rec);
        linearLayoutManager=new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(activityAdapter);

        initBanner(view);

        listener=new RetrofitListener<List<Activity>>() {
            @Override
            public void onResponse(List<Activity> list) {
                activityAdapter.setData(list);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        activityListModel=new ActivityListModel();
        activityListModel.getActivityList(listener);
        return view;
    }



    public void initBanner(View view){
        banner=(Banner)view.findViewById(R.id.activity_bunner);//
        listPath=new ArrayList<>();//图片地址

        listPath.add("http://10.0.2.2/YueJian02/public/static/ActivityLBT/5.jpg");
        listPath.add("http://10.0.2.2/YueJian02/public/static/ActivityLBT/6.jpg");
        listPath.add("http://10.0.2.2/YueJian02/public/static/ActivityLBT/7.jpg");
        listPath.add("http://10.0.2.2/YueJian02/public/static/ActivityLBT/8.jpg");
        //设置内置样式，共有六种可以点入方法内逐一体验使用。
        banner.setBannerStyle(BannerConfig.NUM_INDICATOR);
        //图片加载器类
        banner.setImageLoader(new GlideImageLoader());
        //地址
        banner.setImages(listPath);
        //设置轮播的动画效果，内含多种特效，可点入方法内查找后内逐一体验
        banner.setBannerAnimation(Transformer.DepthPage);
        //间隔时间
        banner.setDelayTime(2000);
        //设置指示器的位置，小点点，左中右。
        //banner.setIndicatorGravity(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE);
        banner.start();
    }

    //图片加载器类
    public class GlideImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {
            Picasso.with(context).load((String)path).into(imageView);
        }
    }


}
